package Hot100;

public class trap_water {
    public static void main(String[] args) {
        int height[] = {0,1,0,2,1,0,1,3,2,1,2,1};
        System.out.println(trap(height));

    }
    public static int trap(int[] height) {
        int temp = 0;
        int sum = 0;
        int maxheight = 0;
        for (int i = 0; i < height.length; i++) {
            if(height[i] > maxheight)
                maxheight = height[i];
        }
        int count = 0;
        for (int i = 1; i <= maxheight; i++) {
            temp = 0;
            count = 0;
            for (int j = 0; j < height.length; j++) {
                if(count != 0){
                    if(height[j] < i)
                        temp++;
                    if(height[j] >= i){
                        sum += temp;
                        temp = 0;
                    }
                }
                if(height[j] >= i)
                    count++;
            }
        }
        return sum;
        
    }

}
